<?php
class Login extends CI_Controller {

 function __construct()
 {
  	parent::__construct();
 }

 public function index()
 {
 	//checkLogin();
 	$this->load->helper("captcha");
 	$cdata = array(
 			'img_path' => './captcha/',
 			'img_url' => './captcha/',
 			'img_width' => 100,
 			'img_height' => 20
 	);
 	 	
 	$data['captcha'] = create_captcha($cdata);
 	$_SESSION['captcha_word'] = $data['captcha']['word'];
  	$this->load->view('login_index',$data);
 }
 public function captcha(){
 	$this->load->helper("captcha");
 	$cdata = array(
 			'img_path' => './captcha/',
 			'img_url' => './captcha/',
 			'img_width' => 100,
 			'img_height' => 20
 	);
 	
 	$data['captcha'] = create_captcha($cdata);
 	$_SESSION['captcha_word'] = $data['captcha']['word'];
 	echo $data['captcha']['image'];exit;
 }
 public function signin(){ 	
 	if($_POST){
 		//验证验证码
 		if(!isset($_SESSION['captcha_word'],$_POST['captcha']) || strtolower($_SESSION['captcha_word']) != strtolower($_POST['captcha'])){
 			mcmessage_error("验证码不正确","./index.php?c=login&a=index");
 		}
 		$username = isset($_POST['username'])?$_POST['username']:'';
 		$password = isset($_POST['password'])?$_POST['password']:'';
 		$this->load->model("AdminModel");
 		$data = $this->AdminModel->getRow("select id,password,username,salt,super from {$this->AdminModel->getTable()} where username='$username'");
 		if($data && $this->common->md5Password($password,$data['salt']) == $data['password']){ 			 			 			 		
 			setLoginSession($data['id'],$data["username"],$data['super']);
 			//如果点击了记住我
 			if(isset($_POST['remember']))
 				rememberMe($data['id'],$data['salt']); 			
 		}else{
 			mcmessage_error("用户名或密码不正确","./index.php?c=login&a=index");
 		}
 		header("location:/index.php");
 	}
 	header("location:/index.php");
 }
 
 public function logout(){
 	unsetLoginSession();
 	unsetLoginCookie();
 	header("location:/index.php?c=login");
 }
}
?>